﻿using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using MyMES.Dto;
using MyMES.Infrastructure;
using MyMES.IServices;
using System.Collections.Generic;
using System.Threading.Tasks;
using VOL.Entity.DomainModels;

namespace VOL.WebApi.Controllers
{
    /// <summary>
    /// 主数据控制器
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class MasterDataController : ControllerBase
    {
        /// <summary>
        /// 供应商仓储
        /// </summary>
        private readonly ISupplierService _supplierService;

        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="supplierService">供应商仓储</param>
        public MasterDataController(ISupplierService supplierService)
        {
            _supplierService = supplierService;
        }

        /// <summary>
        /// 获取供应商管理数据
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public async Task<APIPage<Supplier>> GetSupplierList([FromQuery]GetSupplierPageListDTO request)
        {
            return await _supplierService.GetSupplierList(request);
        }

        /// <summary>
        /// 新增供货商信息
        /// </summary>
        /// <param name="param">供货商参数</param>
        /// <returns></returns>
        [HttpPost]
        public async Task<int> CreateSupplier([FromBody]Supplier param)
        {
            return await _supplierService.CreateSupplier(param);
        }

        /// <summary>
        /// 删除供货商信息
        /// </summary>
        /// <param name="param">供货商参数</param>
        /// <returns></returns>
        [HttpPost]
        public async Task<int> DeleteSupplier([FromBody]Supplier param)
        {
            return await _supplierService.DeleteSupplier(param);
        }

        /// <summary>
        /// 修改供货商信息
        /// </summary>
        /// <param name="param">供货商参数</param>
        /// <returns></returns>
        [HttpPost]
        public async Task<int> UpdateSupplier([FromBody] Supplier param)
        {
            return await _supplierService.UpdateSupplier(param);
        }
    }
}
